#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <assert.h>

int my_strlen(const char* str)
{
	assert(str);
	int count = 0;
	while (*str != '\0') {
		count++;
		str++;
	}
	return count;
}

char* my_strcpy(char* str1, const char* str2)
{
	assert(str1 && str2);
	char* ret = str1;
	while (*str1++ = *str2++);
	*str1 = *str2;
	return ret;
}

int my_strcmp(const char* s1, const char* s2)
{
	while (*s1 == *s2) {
		if (*s1 == '\0')return 0;
		s1++;
		s2++;
	}
	if (*s1 > *s2)return 1;
	else return -1;
}

char* my_strcat(char* dest, const char* src)
{
	char* ret = dest;
	while (*dest) dest++;
	while (*dest++ = *src++);
	return ret;
}

char* my_strstr(const char* str1,const char* str2)
{
	const char* cur = str1;
	const char* s1 = NULL;
	const char* s2 = NULL;
	if (!*str2)return (char*)str1;
	while (*cur) {
		s1 = cur;
		s2 = str2;
		while (*s1 == *s2) {
			s1++;
			s2++;
		}
		if (*s2 == '\0')return (char*)cur;
		cur++;
	}
	return NULL;
}
int main() {
	char arr1[20] = "abcdef";
	char arr2[] = "cd";
	//int len = my_strlen(arr1);
	//printf("%d\n", len);
	//char arr2[20] = { 0 };
	//char* p1 = my_strcpy(arr2, arr1);
	//printf("%s\n", p1);
	//printf("%d\n", my_strcmp(arr1, arr2));
	//printf("%s\n",my_strcat(arr1, arr2));
	printf("%s\n",my_strstr(arr1, arr2));
	
	return 0;
}